package com.gk.ldj.fastdev.testcase;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TestTimer4
{
	public ScheduledExecutorService scheduledExec = Executors.newScheduledThreadPool(1);
	int i = 0;
	int j = 0;
	
	public void launchTimer()
	{
		Runnable task = new Runnable()
		{
			@Override
			public void run()
			{
				System.out.println("launch: " + ++j);
				throw new RuntimeException();
			}
		};
		scheduledExec.scheduleWithFixedDelay(task, 1000 * 5, 1000 * 10, TimeUnit.MILLISECONDS);
	}
	
	public void addOneTask()
	{
		Runnable task = new Runnable()
		{
			@Override
			public void run()
			{
				System.out.println("hello world: " + ++i);
			}
		};
		scheduledExec.scheduleWithFixedDelay(task, 1000 * 1, 1000, TimeUnit.MILLISECONDS);
	}
	
	public static void main(String[] args) throws InterruptedException
	{
		TestTimer4 test = new TestTimer4();
		//test.launchTimer();
		//Thread.sleep(5000);
		test.addOneTask();
	}
}